@extends('admin.common.main')
@section('header')

  <link rel="stylesheet" href="/admin/js/pagination.css">

@endsection

@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <form action="">


            <div class="text-c"> 日期范围：
                <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
                -
                <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
                <input type="text" class="input-text" value="" style="width:250px" placeholder="输入房源名称" id="" name="fang_name">
                <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜房源</button>
            </div>
        </form>
        <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>



             {{-- <a href="{{route('admin.fang.export')}}" class="btn btn-default radius">导出</a>--}}
                <a href="{{route('admin.fang.create')}}"  class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加房源</a></span> <span class="r">共有数据：<strong>88</strong> 条</span> </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="80">ID</th>
                    <th width="100">房源名称</th>
                    <th width="40">房源校区</th>
                    <th width="40">房源状态</th>
                    <th width="90">房源地址</th>


                    <th width="200">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $key=>$val)
                    @if(isset($val['_source']))
                    <tr class="text-c">
                        <td><input type="checkbox" value="1" name=""></td>
                        <td>{{$val['_source']['id']}}</td>
                        <td>{!! $val['highlight']['fang_name'][0] !!}}</td>
                        <td> {{$val['_source']['fang_xiaoqu']}}</td>
                        <td>
                            // Es 中的 极点即改  没有写 数据和mysql不同步
                            @if($val['_source']['fang_status']==1)
                                <span class="btn btn-default" fang_status="0" fang_id="{{$val['_source']['id']}}" onclick="chang_status(this)">已出租</span>
                            @else

                                <span class="btn btn-warning" fang_status="1" fang_id="{{$val['_source']['id']}}" onclick="chang_status(this)">未出租</span>
                            @endif
                        </td>
                        <td>{{$val['_source']['fang_addr']}}</td>

                        <td class="td-manage">

                            <a href="javascript:;" onclick="member_del(this,'1')" class="label label-default radius" style="text-decoration:none">编辑</a>
                            <a href="javascript:;" onclick="member_del(this,'1')" class="label label-default radius" style="text-decoration:none">删除</a>

                        </td>
                    </tr>
                    @else
                        <tr class="text-c">
                            <td><input type="checkbox" value="1" name=""></td>
                            <td>{{$val['id']}}</td>
                            <td>{{$val['fang_name']}}</td>
                            <td> {{$val['fang_xiaoqu']}}</td>
                            <td>
                                @if($val['fang_status']==1)
                                    <span class="btn btn-default" fang_status="0" fang_id="{{$val['id']}}" onclick="chang_status(this)">已出租</span>
                                @else

                                    <span class="btn btn-warning" fang_status="1" fang_id="{{$val['id']}}" onclick="chang_status(this)">未出租</span>
                                @endif

                            </td>
                            <td>{{$val['fang_addr']}}</td>

                            <td class="td-manage">

                                <a href="javascript:;" onclick="member_del(this,'1')" class="label label-default radius" style="text-decoration:none">编辑</a>
                                <a href="javascript:;" onclick="member_del(this,'1')" class="label label-default radius" style="text-decoration:none">删除</a>

                            </td>
                        </tr>


                        @endif

                @endforeach
                </tbody>
            </table>
            @if(!isset($on))
            {{$data  -> links()}}
                @endif
        </div>
    </div>

@endsection


@section('js')
    <script type="text/javascript">

        /**
         * 极点即改  更改的是数据库 没更改Es 库
         * @param ret
         */
    function chang_status(ret) {

        let id = $(ret).attr('fang_id');
        let status = $(ret).attr('fang_status');

        $.ajax({
            url:"{{route('admin.fang.chang_status')}}",
            type:"PUT",
            dataType:"json",
            data:{
                id,status,_token:"{{csrf_token()}}"
            },
            success:res=>{
                if(res.error_code == 0){

                   if(status==1){

                       $(ret).removeClass('btn-warning').addClass('btn-default');
                       $(ret).attr('fang_status',0)
                       $(ret).text("已出租")
                       layer.msg(res.msg)
                   }else{

                       $(ret).removeClass('btn-default').addClass('btn-warning');
                       $(ret).attr('fang_status',1)
                       $(ret).text("未出租")
                       layer.msg(res.msg)
                   }

                }


            }


        })

    }


    </script>

@endsection

